﻿using System.Diagnostics;
using XFPPT.NET;
using XFPPT.NET.Enum;
using XFPPT.NET.Models;


namespace ConsoleTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            String appId = "appId";
            String secret = "secret";

            XFPPTv2ApiClient xFPPTv2ApiClient = new XFPPTv2ApiClient(appId, secret);

            /*选择模板*/
            TemplateListResponse templateListResponse = xFPPTv2ApiClient.GetTemplateList(style: TemplateStyle.商务, color: TemplateColor.蓝色, industry: TemplateIndustry.科技互联网);
            string? templateId = null;
            try
            {
                templateId = templateListResponse.data!.records[1]!.templateIndexId;
            }
            catch (Exception) { }

            Console.WriteLine("templateId: " + templateId);

            /*生成PPT*/
            PPTCreateRequest pPTCreateRequest = new PPTCreateRequest();
            pPTCreateRequest.query = "不需要引言，目录标题页码严格使用我上传的文件！";
            pPTCreateRequest.file= FileToBinaryConverter.ConvertFileToBinary("demo.txt");
            pPTCreateRequest.fileName ="demo.txt";
            pPTCreateRequest.templateId = templateId;
            pPTCreateRequest.search = true;
            pPTCreateRequest.author = "zjw";
            pPTCreateRequest.isFigure = true;
            pPTCreateRequest.aiImage = AiImage.advanced;
            pPTCreateRequest.isCardNote = true;

            PPTCreateResponse pPTCreateResponse= xFPPTv2ApiClient.PPTCreate(pPTCreateRequest);
            string sid = pPTCreateResponse.data!.sid!;
            Console.WriteLine("sid: "+sid);

            /*获取pptUrl*/
            string? pptUrl =string.Empty;
            while (true) 
            {
                ProgressResponse progressResponse= xFPPTv2ApiClient.GetProgress(sid);
                try
                {
                    pptUrl = progressResponse.data!.pptUrl;
                }
                catch (Exception)
                {

                   // throw;
                }
               
                if (!string.IsNullOrWhiteSpace(pptUrl)) 
                { 
                    break;
                }

                Console.WriteLine("donePages:" + progressResponse.data!.donePages+"/totalPages: " + progressResponse.data!.totalPages);
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                while (stopwatch.ElapsedMilliseconds < 3000)
                {
                    // Do nothing or perform light operations.
                  
                }
                stopwatch.Stop();

            }

            Console.WriteLine("pptUrl: " + pptUrl);
            //File.WriteAllText("output.txt", pptUrl);
            File.AppendAllText("output.txt", pptUrl);
            //Console.WriteLine("appId:"+xFPPTv2ApiClient.TempAuthInfo.appId);
            //Console.WriteLine("timestamp:"+xFPPTv2ApiClient.TempAuthInfo.timestamp);
            //Console.WriteLine("signature:"+xFPPTv2ApiClient.TempAuthInfo.signature);
            Console.ReadLine();
            Console.ReadKey();

        }
    }
}
